import Vue from 'vue'
import VueRouter from 'vue-router'
/* Layout */
import Layout from '@/views/layout/Layout'
import Layout2 from '@/views2/layout/Layout'
import adminLogin from  '@/views/login/index'
Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const ConstantRoutes = [
  {
    path: '/',
    redirect: '/index',
    name: '首页-index',

  },
  {
    path: '/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    hidden: true,
    component: () => import( '@/components/login/index')
  },
  {
    path: '/admin/login',
    name: 'login-admin',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    hidden: true,
    component:adminLogin
  },
  {
    path: '/index',
    name: 'index',
    redirect: "/index/index_2",
    meta: { title: '首页', icon: 'example' },
    hidden: true,

    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component:()=> import ('@/fortendView/index_test/index'),
    children: [{
      path: 'index_1',
      name:'index_1',
      meta: { title: 'index_1', icon: 'example' },
      component: ()=> import ('@/fortendView/index_1/index')

    },
      {
        path: 'index_2',
        name:'index_2',
        meta: { title: 'index_2', icon: 'example' },
        component: ()=> import ('@/fortendView/index_2/index')

      },
      {
        path: 'index_3',
        name:'index_3',
        meta: { title: 'index_3', icon: 'example' },
        component: ()=> import ('@/fortendView/index_3/index')

      },

    ]
  },
  { path: '/404', name:'404',component: () => import('@/views/404'), hidden: true },//hidden 代表不加进dashboard 的siderbar里面
  { path: '/ip', component: () => import('@/fortendView/ip'), hidden: true },
  { path: '/test', component: () => import('@/fortendView/test'), hidden: true },
]

const  adminRoutes=[
  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/dashboard',
    name: 'admin-dashboard',
    hidden: false,
    children: [{
      path: 'dashboard',
      meta: { title: '首页', icon: 'example' },
      component: () => import('@/views/dashboard/index')
    }]
  },
  // {
  //   path: '/admin',
  //   component: Layout,
  //   redirect: '/admin/dashboard',
  //   name: '首页-admin',
  //   // alwaysShow: true,
  //   hidden: false,
  //   meta: { title: '首页', icon: 'example' },
  //   children: [
  //   ]
  // },
  {
    path: '/data',
    component: Layout,
    redirect: '/data/dataManager',
    name: '数据管理',
    alwaysShow: true,
    hidden: false,
    meta: { title: '数据管理', icon: 'example' },
    children: [
      {
        path: `HealthList`,//这里不用加 / ，如果加了会直接代替掉/data/manager
        name: '上报列表',
        component: () => import('@/views/dataManager/HealthList'),
        meta: { title: '上报列表', icon: 'table' }
      },
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/userManager',
    name: '用户管理',
    alwaysShow: true,
    hidden: false,
    meta: { title: '用户管理', icon: 'example' },
    children: [
      {
        path: `UserList`,
        name: '用户列表',
        component: () => import('@/views/userManager/UserInfoList'),
        meta: { title: '用户列表', icon: 'table' }
      },
      {
        path: `importStu`,
        name: '导入学生信息',
        component: () => import('@/views/userManager/importUser'),
        meta: { title: '导入学生信息', icon: 'table' }
      },

    ]
  },
  {
    path: '/myself',
    component: Layout,
    redirect: '/myself/myselfManager',
    name: '个人中心-admin',
    alwaysShow: true,
    hidden: false,
    meta: { title: '个人中心', icon: 'example' },
    children: [
      {
        path: `list-permission`,
        name: 'list-permission',
        component: () => import('@/views/myselfManager/list'),
        meta: { title: '查看权限', icon: 'table' }
      },
      {
        path: `myself`,
        name: 'myself',
        component: () => import('@/views/myselfManager/myself'),
        meta: { title: '个人信息', icon: 'table' }
      },
      {
        path: `addPermission`,
        name: 'addPermission',
        component: () => import('@/views/myselfManager/add'),
        meta: { title: '权限添加', icon: 'table' }
      },

    ]
  },
];

const userRoutes=[
  {
    path: '/userCommon',
    component: Layout2,
    redirect: '/userCommon/dashboard',
    name: 'user-dashboard',
    hidden: false,
    children: [{
      path: 'dashboard',
      meta: { title: '首页', icon: 'example' },
      component: () => import('@/views2/dashboard/index')
    }]
  },
  // {
  //   path: '/userCommon',
  //   component: Layout2,
  //   redirect: '/userCommon/dashboard',
  //   name: 'user-dashboard',
  //   // alwaysShow: true,
  //   hidden: false,
  //   meta: { title: '首页', icon: 'example' },
  //   children: [
  //   ]
  // },
  {
    path: '/myself-user',
    component: Layout2,
    redirect: '/myself-user/myselfManager',
    name: '个人中心——user',
    alwaysShow: true,
    hidden: false,
    meta: { title: '个人管理', icon: 'example' },
    children: [
      {
        path: `basicInfo`,
        name: 'basicInfo',
        component: () => import('@/views2/myselfManager/show'),
        meta: { title: '基本信息', icon: 'table' }
      },
      {
        path: `reportInfo`,
        name: 'reportInfo',
        component: () => import('@/views2/myselfManager/reportInfo'),
        meta: { title: '打卡记录', icon: 'table' }
      },
      {
        path: `update`,
        name: 'updatePassword',
        component: () => import('@/views2/myselfManager/updatePassWord'),
        meta: { title: '修改密码', icon: 'table' }
      },
    ]
  },
];
const finalRoutes=[
  {
    path: '*',
    component: () => import('@/views/404'),
    name: '404页面',
  },
]
const router = new VueRouter({

  routes:ConstantRoutes.concat(adminRoutes).concat(userRoutes).concat(finalRoutes),
  // routes:ConstantRoutes,
  mode:"history",
})
/*
const createRouter=()=>new VueRouter({
  ConstantRoutes,
  mode:"history",
  scrollBehavior: () => ({ y: 0 }),
})
*/


/*const router = createRouter();*/

export default router

/*重置路由*/
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

//这里存在两种后台路由，用于动态添加路由
export {userRoutes,adminRoutes};
